const router = require("koa-router")()
const sql = require("../lib/mysql")

// 获取当前剩余测试私钥的数量
router.get("/", async ctx => {
  let res = await sql.cSelect("*", "trailKey")

  ctx.body = {state: 1, data: res.length}
})

// 获取一个测试私钥
router.get("/getKey", async ctx => {
  let res = await sql.cSelect("*", "trailKey")
  res = res[0]

  if (res.length <= 0) {
    ctx.body = {state: 0, data: "测试私钥已用完，如果您想继续使用，请联系开发者。"}
  }

  await sql.cDelete("trailKey", `id="${res.id}"`)

  ctx.body = {state: 1, data: res}
})

module.exports = router.routes()